package com.qdaily.ui.util;

import android.support.annotation.Nullable;

import com.qdaily.supportlibrary.util.QLog;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by song on 15/5/12.
 */
public class QDRegUtil {

    //获取文章的host
    public static String getQArticleHost(String url){
        if(url==null||url.trim().equals("")){
            return "";
        }
        String host = "";
        Pattern p = Pattern.compile("(http://|https://)?([^/]*)",Pattern.CASE_INSENSITIVE);;
        Matcher matcher = p.matcher(url);
        if(matcher.find()){
            host = matcher.group();
        }
        return host;
    }

    //获取文章链接点击的效果
    @Nullable
    public static String[] getQArticleUrlType(String url){
        if(url == null || url.trim().equals("")){
            return null;
        }

        String prefix = "qdaily.com" + "/display/|" + "qdaily.com" + "/webapp/";
        Pattern p = Pattern.compile("(" + prefix +")(articles/|papers/|cards/)(\\d*)",Pattern.CASE_INSENSITIVE);;
        Matcher matcher = p.matcher(url);
        if(matcher.find())
        {
            String[] strings = matcher.group().split("/");
            if (strings.length == 4)
            {
                String[] resultArray = {strings[2], strings[3]};
                QLog.w("getQArticleUrlType:", url + "---->" + resultArray[0] + "," + resultArray[1]);
                return resultArray;
            }
        }
        return null;
    }
}
